package neu.soft.controller;

import neu.soft.entity.DO.ReceiptJournal;
import neu.soft.service.FinancialService;
import neu.soft.service.ReceiptJournalService;
import neu.soft.vo.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/return")
public class PayController {

    @Autowired
    FinancialService financialService;

    @Autowired
    ReceiptJournalService receiptJournalService;

    @PostMapping
    public ResultBean update(@RequestBody Map<String,Object> map){
        System.out.println("------------------------------------------");
        System.out.println(map);
        String oid = (String) map.get("oid");

        ReceiptJournal receiptJournal = receiptJournalService.findById(oid);
        BigDecimal bigDecimal = receiptJournal.getTotalPay();
        financialService.pay(bigDecimal);
        return ResultBean.success();
    }
}
